import * as actionTypes from "./constants";

import { getTabList, getRankingList } from "@/services/ranking";

/**
 * 
 * @returns 左侧榜单列表
 */
export function getTabsRequest() {
  return dispatch => {
    getTabList().then(res => {
      dispatch(changeTabListAction(res.list))
    })
  }
};
const changeTabListAction = (tabList) => ({
  type: actionTypes.CHANGE_TAB_LIST,
  tabList
});

/**
 * 
 * @param {榜单id} id 
 * @returns 右侧列表
 */
export function getRankingRequest(id) {
  return dispatch => {
    getRankingList(id).then(res => {
      dispatch(changeRankingAction(res.playlist))
    })
  }
};
const changeRankingAction = (listInfo) => ({
  type: actionTypes.CHANGE_RANKING_LIST,
  listInfo
});

/**
 * 
 * @param {索引} index 
 * @returns 点击当前位置
 */
export const changeCurrentIndex = (index) => ({
  type: actionTypes.CHANGE_CURRENT_INDEX,
  index
})